// reducers/user.ts
import { UserState, UserAction } from '../types';
 
// 初始状态
const initialUserState: UserState = {
  id: null,
  name: null,
};
 
// User Reducer
export const userReducer = (
  state: UserState = initialUserState,
  action: UserAction
): UserState => {
  switch (action.type) {
    case 'user/login':
      return { ...state, ...action.payload };
    case 'user/logout':
      return initialUserState;
    default:
      return state;
  }
};